-
Notifications
You must be signed in to change notification settings - Fork 635
feat(byte_array): add get(usize)
and index(usize)
to ByteSpan
#8427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: gilad/09-14-feat_byte_array_add_slice_
Are you sure you want to change the base?
feat(byte_array): add get(usize)
and index(usize)
to ByteSpan
#8427
Conversation
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
f840c46
to
bcf3c7d
Compare
d2487b7
to
235db8b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TomerStarkware reviewed 2 of 2 files at r2, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @orizi)
235db8b
to
eeaa0bf
Compare
bcf3c7d
to
04b763d
Compare
04b763d
to
c03411e
Compare
45abe52
to
afd7694
Compare
8885cbb
to
a4243a8
Compare
9ab073e
to
b38e4cc
Compare
a4243a8
to
6769953
Compare
b38e4cc
to
20ea89a
Compare
6769953
to
19ce8b6
Compare
20ea89a
to
bc5dfbf
Compare
19ce8b6
to
4bf4932
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orizi reviewed all commit messages.
Reviewable status: 0 of 2 files reviewed, 2 unresolved discussions (waiting on @TomerStarkware)
corelib/src/byte_array.cairo
line 703 at r4 (raw file):
fn at(self: @ByteSpan, index: usize) -> Option<u8> { let actual_index = index.checked_add(upcast(self.first_char_start_offset))?; let (word_index, index_in_word) = DivRem::div_rem(actual_index, BYTES_IN_BYTES31_NONZERO);
use bounded_int::div_rem
and get index_in_word
in [0,30]
range.
you can use bounded_int::constrain
later to decide if it is accessing the lower or upper word.
Code quote:
let (word_index, index_in_word) = DivRem::div_rem(actual_index, BYTES_IN_BYTES31_NONZERO);
corelib/src/byte_array.cairo
line 713 at r4 (raw file):
if word_index == self.data.len() && index_in_word < upcast(self.remainder_len) { // index_in_word is from MSB, we need index from LSB. let index_in_remainder = upcast(self.remainder_len) - 1 - index_in_word;
bounded_int::sub as well.
Code quote:
let index_in_remainder = upcast(self.remainder_len) - 1 - index_in_word;
bc5dfbf
to
50fdc8e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TomerStarkware reviewed 3 of 3 files at r6, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @orizi)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orizi reviewed 1 of 3 files at r6, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @giladchase)
corelib/src/byte_array.cairo
line 917 at r6 (raw file):
} pub fn bytespan_get_usize(self: @ByteSpan, index: usize) -> Option<u8> {
doc and improve name.
e37a182
to
a29cd34
Compare
1d9e119
to
0760802
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @orizi)
corelib/src/byte_array.cairo
line 917 at r6 (raw file):
Previously, orizi wrote…
doc and improve name.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orizi reviewed 3 of 3 files at r7, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @giladchase)
0760802
to
fdf41e3
Compare
a29cd34
to
2280b52
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orizi reviewed 4 of 4 files at r8, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @giladchase)
2280b52
to
02d1817
Compare
fdf41e3
to
b557e75
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orizi reviewed 2 of 3 files at r9, all commit messages.
Reviewable status: 4 of 5 files reviewed, 1 unresolved discussion (waiting on @TomerStarkware)
corelib/src/byte_array.cairo
line 1014 at r9 (raw file):
// For byte_at: div_rem of (usize + BoundedInt<0,30>) by 31 const USIZE_PLUS_30_DIV_31: felt252 = 0x8421085; // (usize::MAX + 30) / 31 = 138547333
should work.
Suggestion:
((Bounded::<usize>::MAX + 30) / 31).into();
02d1817
to
826e33e
Compare
5148fd0
to
2dd37d7
Compare
826e33e
to
1b13525
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 4 of 5 files reviewed, 1 unresolved discussion (waiting on @orizi and @TomerStarkware)
corelib/src/byte_array.cairo
line 1014 at r9 (raw file):
Previously, orizi wrote…
should work.
Messes up semantic:
thread '<unnamed>' panicked at crates/cairo-lang-semantic/src/items/constant.rs:839:19:
Variant extract failed: `Extern(ExternFunctionId(f830))` is not of variant `GenericFunctionId::Impl`
When debugging it i switched it the +30
to -30
and it passed semantic (but failed in the logic of course), meaning probably semantic is having problems deciding what type to evaluate this to (maybe it tries to evaluate the type after the addition before taking the Div into account?).
Maybe this is a bug in semantic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orizi reviewed all commit messages.
Reviewable status: 4 of 5 files reviewed, 1 unresolved discussion (waiting on @giladchase and @TomerStarkware)
corelib/src/byte_array.cairo
line 1014 at r9 (raw file):
Previously, giladchase wrote…
Messes up semantic:
thread '<unnamed>' panicked at crates/cairo-lang-semantic/src/items/constant.rs:839:19: Variant extract failed: `Extern(ExternFunctionId(f830))` is not of variant `GenericFunctionId::Impl`
When debugging it i switched it the
+30
to-30
and it passed semantic (but failed in the logic of course), meaning probably semantic is having problems deciding what type to evaluate this to (maybe it tries to evaluate the type after the addition before taking the Div into account?).
Maybe this is a bug in semantic.
lets go with `(Bounded::::MAX / 31 + 1).into(); instead.
1b13525
to
ec6fe60
Compare
2dd37d7
to
e75d288
Compare
ec6fe60
to
2a75931
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 4 of 5 files reviewed, 1 unresolved discussion (waiting on @orizi and @TomerStarkware)
corelib/src/byte_array.cairo
line 1014 at r9 (raw file):
Previously, orizi wrote…
lets go with `(Bounded::::MAX / 31 + 1).into(); instead.
Nice, done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orizi reviewed 1 of 1 files at r12, all commit messages.
Reviewable status: 4 of 5 files reviewed, all discussions resolved (waiting on @TomerStarkware)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orizi reviewed 1 of 1 files at r11.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @giladchase)
No description provided.